//
//  WeiXinController.swift
//  WeChat
//
//  Created by henaihan on 2017/10/23.
//  Copyright © 2017年 henaihan. All rights reserved.
//

import UIKit

class WeiXinController: UITableViewController {
    @IBOutlet weak var search: UISearchBar!
    
    lazy var allArr: NSMutableArray = { () -> NSMutableArray in
        //创建模型数组
        let tempallArr = NSMutableArray()
        //1.获取数据
        let strPath = Bundle.main.path(forResource: "WeiXin", ofType: "plist")
        //2.读取文件
        let arr: NSMutableArray = NSMutableArray(contentsOfFile: strPath!)!
        //3.解析文件
        for dict in arr{
            //let model: WeiXinModel = WeiXinModel.weixinModelWithDict(dict as! NSDictionary)
            let model: WeiXinModel = WeiXinModel(dict: (dict as! NSDictionary) as! [String : AnyObject])
            tempallArr.add(model)
        }
        return tempallArr
    }()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "微信"
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.allArr.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = WeiXinCell.createCell(tableView: tableView)
        let model: WeiXinModel = allArr[indexPath.row] as! WeiXinModel
        cell.model = model
        
        return cell
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }
    
    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            allArr.removeObject(at: indexPath.row)
            tableView.deleteRows(at: [indexPath as IndexPath], with: .fade)
        } else if editingStyle == .insert {}
    }
}


